//
//  MarketHeaderCell.m
//  yigou
//
//  Created by wangdianlei on 2017/1/5.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "MarketHeaderCell.h"
#import "MMMarketHeader.h"
#import "MMMarketNew.h"
#import "GoodDetailViewController.h"
#import "CustomWebViewController.h"

@implementation MarketHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)createWithImg:(UIImageView *)img Title:(NSString *)title {
    float W = img.frame.size.width;
    float H = img.frame.size.height;
    img.layer.cornerRadius = 8;
    img.layer.masksToBounds = YES;
    UILabel *label = [[UILabel alloc]init];
    label.textColor = [UIColor whiteColor];
    label.text = title;
    label.frame = CGRectMake(0, H/2-10, W, 20);
    label.font = [UIFont systemFontOfSize:17];
    label.textAlignment = NSTextAlignmentCenter;
    [img addSubview:label];
    img.image = [UIImage imageNamed:@"placeholder"];
}
- (void)fillData {
    
    
    if (self.cycleScrollView) {
        [self.cycleScrollView removeFromSuperview];
        self.cycleScrollView = nil;
    }
    
    CGFloat w = ScreenWidth;
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, 188) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    //cycleScrollView2.titlesGroup = titles;
    self.cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    //cycleScrollView.autoScrollTimeInterval = 4.0;
    NSMutableArray *imgurls = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < MARKETDATA.marketHeaders.count; i++) {
        MMMarketHeader *one = MARKETDATA.marketHeaders[i];
        [imgurls addObject:one.pic_url];
    }
    self.cycleScrollView.imageURLStringsGroup = imgurls;
    [self.contentView addSubview:self.cycleScrollView];
    
    //         --- 模拟加载延迟
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //        cycleScrollView2.imageURLStringsGroup = imagesURLStrings;
    //    });
//    self.zhiboImg
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    DYLog(@"---点击了第%ld张图片", (long)index);
    MMMarketHeader *one = MARKETDATA.marketHeaders[index];
    
    if (self.vc) {
        CustomWebViewController *vc = [[CustomWebViewController alloc] initWithNibName:@"CustomWebViewController" bundle:nil];
        vc.url = one.action_url;
        [self.vc.navigationController pushViewController:vc animated:YES];
    }
//    if (self.vc) {
//        GoodDetailViewController *gooddetail = [[GoodDetailViewController alloc] initWithNibName:@"GoodDetailViewController" bundle:nil];
//        gooddetail.gooddata = gooddata;
//        gooddetail.goodname = gooddata.goods_name;
//        gooddetail.productId = gooddata.goods_id;
//        [self.vc.navigationController pushViewController:gooddetail animated:YES];
//    }
}

@end
